const utils = require('./utils');
process.title = "node-pawer"

const start = async function () {
  const browser = await utils.launch();

  const ebesucher = 'http://www.ebesucher.com/surfbar/foolishchow';
  const pageEbesucher = await utils.newPage(browser);

  pageEbesucher.on('framenavigated', (frame) => {
    frame.evaluate(() => {
      window.chrome = {
        name: 'chrome'
      }
      setInterval(() => {
        if ($ && $('#surfbar_running').length > 0 && $('#surfbar_running').css('display') == "none") {
          $("#surf_now_button").click();
        }
      }, 5000);
    })
  });
  pageEbesucher.on('console', e => {
    console.info(`console ==>  ${e.text()}`)
  })
  pageEbesucher.goto(ebesucher);
  await pageEbesucher.focus();

  browser.defaultBrowserContext()
  setTimeout(async () => {
    await browser.close();
    start();
  }, 60 * 60 * 1000);
}
start();